#!/bin/bash
. ./path.sh

if [ ! -f ./goofys ]; then
	wget https://github.com/kahing/goofys/releases/latest/download/goofys
	chmod +x ./goofys
fi

if [ ! -d $chiapath ];then
   sudo mkdir -p $chiapath
   sudo ./goofys $bucket $chiapath
fi

sudo apt install -y nvme-cli

tempath=nvme0n1

if [ -e /dev/$tempath ];then
	echo "exist here"
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme1n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme2n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme3n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme4n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme5n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme6n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi

tempath=nvme7n1

if [ -e /dev/$tempath ];then
	if [ ! -d /home/$tempath ];then
		sudo mkdir -p /home/$tempath
	fi
	# Find ephemeral storage (assumes a single ephemeral disk)
	# and format it (assumes this is run on first-boot in user-data, so the disk is not formatted)
	#EPHEMERAL_DISK=$(sudo nvme list | grep 'Amazon EC2 NVMe Instance Storage' | awk '{ print $1 }')
        sudo mkfs.ext4 /dev/$tempath
        sudo mount -t ext4 /dev/$tempath /home/$tempath
fi
